package com.example.threadblock;

/**
 * @author zhanghui
 * @date 2021/11/30 13:50
 */
public class JoinDemo {
    public static final int SLEEP_TIME = 500;

    static class HotWaterThread extends Thread {
        public HotWaterThread() {
            super("** 烧水-Thread");
        }

        @Override
        public void run() {
            System.out.println("洗好水壶");
            System.out.println("灌上凉水");
            System.out.println("放在火上");
            try {
                Thread.sleep(SLEEP_TIME);
            } catch (InterruptedException e) {
                System.out.println("** 烧水-Thread 异常被中断");
            }
            System.out.println("水开了");
        }
    }

    static class WashThread extends Thread {
        public WashThread() {
            super("$$ 清洗-Thread");
        }

        @Override
        public void run() {
            System.out.println("洗茶壶");
            System.out.println("洗茶杯");
            System.out.println("拿茶叶");
            try {
                Thread.sleep(SLEEP_TIME * 4);
            } catch (InterruptedException e) {
                System.out.println("$$ 清洗-Thread 异常被中断");
            }
            System.out.println("洗完了");
        }
    }

    public static void main(String[] args) {
        Thread hotWaterThread = new HotWaterThread();
        Thread washThread = new WashThread();
        hotWaterThread.start();
        washThread.start();

        try {
            hotWaterThread.join();
            System.out.println("=======完成烧水========");
            washThread.join();
            System.out.println("=======完成清洗========");
            System.out.println("泡茶喝");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
